<template>
  <div>
    <van-nav-bar
      title="意见和反馈"
      left-arrow
      @click-left="$router.push('/user')"
      @click-right="handleSubmit()"
    >
      <p slot="right" class="text-red">提交</p>
    </van-nav-bar>
    <div class="m-t-5 p-10 p-r-15">
      <van-field v-model="message" type="textarea" placeholder="请输入意见和建议反馈, 至少10个字" rows="4" autosize />
      <p class="text-right m-t-10 text-grey fs-rem-12px">{{message.length}} / 200</p>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      message: ''
    }
  },
  methods: {
    async handleSubmit () {
      if (this.message.length >= 10) {
        let { status, message } = await this.$api.post('/ts/add', {
          option: this.message
        })
        if (status === 0) {
          this.$toast.success({
            message,
            duration: 1000
          })
          setTimeout(() => {
            this.$router.push('/user')
          }, 500)
        }
      } else {
        this.$toast('至少输入10个字')
      }
    }
  }
}
</script>
